﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using gfLibrary;
using DBUtility;
using Model;
using BLL;

namespace GreatGF
{
    public partial class DEV_STANDARD_ZYJS_Insert_Update : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {

                string strMode = Request["m"];

                if((strMode == "u")||(strMode == "b")||(strMode == "r"))
                {
                    string strId = Request["UniqueKey"];

                    DEV_STANDARD_ZYJS_BLL m_DEV_STANDARD_ZYJS_BLL = new DEV_STANDARD_ZYJS_BLL();

                    if(m_DEV_STANDARD_ZYJS_BLL.Exists(Convert.ToInt32(strId)) == true)
                    {
                        DEV_STANDARD_ZYJS m_DEV_STANDARD_ZYJS = new DEV_STANDARD_ZYJS();
                        m_DEV_STANDARD_ZYJS = m_DEV_STANDARD_ZYJS_BLL.GetModel(Convert.ToInt32(strId));

                        txtID.Text = m_DEV_STANDARD_ZYJS.ID.ToString();
                        txtSEARCH_CONDITION.Text = m_DEV_STANDARD_ZYJS.SEARCH_CONDITION;
                        txtZXMC.Text = m_DEV_STANDARD_ZYJS.ZXMC;
                        txtZYJSXZ.Text = m_DEV_STANDARD_ZYJS.ZYJSXZ;
                        txtAREA_NAME.Text = m_DEV_STANDARD_ZYJS.AREA_NAME;
                        //txtIS_SHOW.Text = m_DEV_STANDARD_ZYJS.IS_SHOW.ToString();                       
                        //txtUTYPE.Text = m_DEV_STANDARD_ZYJS.UTYPE.ToString();
                        if (m_DEV_STANDARD_ZYJS.IS_SHOW == 0)
                            DropDownIS_SHOW.SelectedIndex = 1;
                        else
                            DropDownIS_SHOW.SelectedIndex = 2;
                        if (m_DEV_STANDARD_ZYJS.UTYPE == 0)
                            DropDownListUTYPE.SelectedIndex = 1;
                        else
                            DropDownListUTYPE.SelectedIndex = 2;

                    }
                    else
                    {
                        gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                        gfAjaxJs.SetGoToUrl(this.UpdatePanel1, "DEV_STANDARD_ZYJS_List.aspx");
                    }

                    if((strMode == "b")||(strMode == "r"))
                    {
                        txtID.ReadOnly = true;
                        txtID.CssClass = "csstextboxreadonly";
                        txtSEARCH_CONDITION.ReadOnly = true;
                        txtSEARCH_CONDITION.CssClass = "csstextboxreadonly";
                        txtZXMC.ReadOnly = true;
                        txtZXMC.CssClass = "csstextboxreadonly";
                        txtZYJSXZ.ReadOnly = true;
                        txtZYJSXZ.CssClass = "csstextboxreadonly";
                        //txtIS_SHOW.ReadOnly = true;
                        //txtIS_SHOW.CssClass = "csstextboxreadonly";
                        //txtAREA_NAME.ReadOnly = true;
                        //txtAREA_NAME.CssClass = "csstextboxreadonly";
                        //txtUTYPE.ReadOnly = true;
                        //txtUTYPE.CssClass = "csstextboxreadonly";
                        DropDownIS_SHOW.Enabled = false;
                        DropDownIS_SHOW.CssClass = "csstextboxreadonly";
                        txtAREA_NAME.ReadOnly = true;
                        txtAREA_NAME.CssClass = "csstextboxreadonly";
                        DropDownListUTYPE.Enabled = false;
                        DropDownListUTYPE.CssClass = "csstextboxreadonly";
                        btnSave.Visible = false;
                    }

                    if(strMode == "r")
                    {
                        btnBack.Visible = false;
                    }
                }
                if (strMode == "i")
                {
                    lblOperateType.Text = "添加";
                }
                if (strMode == "b" || strMode == "r")
                {
                    lblOperateType.Text = "查看";
                }
                if (strMode == "u")
                {
                    lblOperateType.Text = "修改";
                }
            }

            btnBack.Attributes["onclick"] = "javascript:window.location.href='DEV_STANDARD_ZYJS_List.aspx';return false;";
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strID = txtID.Text.Trim();
            string strSEARCH_CONDITION = txtSEARCH_CONDITION.Text.Trim();
            string strZXMC = txtZXMC.Text.Trim();
            string strZYJSXZ = txtZYJSXZ.Text.Trim();
            string strAREA_NAME = txtAREA_NAME.Text.Trim();
            //string strIS_SHOW = txtIS_SHOW.Text.Trim();          
            //string strUTYPE = txtUTYPE.Text.Trim();
            string strUTYPE, strIS_SHOW;
            if (DropDownIS_SHOW.SelectedIndex == 1)
                strIS_SHOW = "0";
            else
                strIS_SHOW = "1";
            if (DropDownListUTYPE.SelectedIndex == 1)
                strUTYPE = "0";
            else
                strUTYPE = "1";


            if (gfValidate.Is_Integer(strIS_SHOW) == false)
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "[IS_SHOW]不是有效的数字格式。");
                return;
            }
            if (gfValidate.Is_Integer(strUTYPE) == false)
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "[UTYPE]不是有效的数字格式。");
                return;
            }

            DEV_STANDARD_ZYJS m_DEV_STANDARD_ZYJS = new DEV_STANDARD_ZYJS();
            DEV_STANDARD_ZYJS_BLL m_DEV_STANDARD_ZYJS_BLL = new DEV_STANDARD_ZYJS_BLL();

            m_DEV_STANDARD_ZYJS.SEARCH_CONDITION = strSEARCH_CONDITION;
            m_DEV_STANDARD_ZYJS.ZXMC = strZXMC;
            m_DEV_STANDARD_ZYJS.ZYJSXZ = strZYJSXZ;
            m_DEV_STANDARD_ZYJS.IS_SHOW = Convert.ToInt32(strIS_SHOW);
            m_DEV_STANDARD_ZYJS.AREA_NAME = strAREA_NAME;
            m_DEV_STANDARD_ZYJS.UTYPE = Convert.ToInt32(strUTYPE);

            if (string.IsNullOrEmpty(strID) == true)
            {
                strID = "-1";
            }

            if (m_DEV_STANDARD_ZYJS_BLL.Exists(Convert.ToInt32(strID)) == false)
            {
                //m_DEV_STANDARD_ZYJS.ID = m_DEV_STANDARD_ZYJS_BLL.GetMax_ID();

                if (m_DEV_STANDARD_ZYJS_BLL.Insert(m_DEV_STANDARD_ZYJS) == true)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "新增成功！");
                    txtID.Text = m_DEV_STANDARD_ZYJS.ID.ToString();
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "新增失败！");
                }
            }
            else
            {
                if (m_DEV_STANDARD_ZYJS_BLL.Update(m_DEV_STANDARD_ZYJS, Convert.ToInt32(strID)) == true)
                {
                     gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "更新成功！");
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "更新失败！");
                }
            }
        }
    }
}
